// 引入 router 在vuex内使用router跳转
import router from '@/router'

import http from '@/assets/js/requset'

let tokenKey = 'config'
let tokenStr = window.sessionStorage.getItem(tokenKey)
let tokenVal = {}
if (tokenStr) {
    tokenVal = JSON.parse(tokenStr)
}

const config = {
    // 如果为true---->调用方法需添加命名空间 如tabviews/createTab
    namespaced: true,
    state: {
        baseURL: tokenVal.baseURL,
        ossURL: tokenVal.ossURL,
        ossImage: tokenVal.ossImage,
        ossFolder: tokenVal.ossFolder,
        enable: tokenVal.enable || true,
    },

    // dispatch 触发--->actions 异步变更
    actions: {
        //   登录记录验证
        cache({ commit }, data) {
            if (data) {
                commit('CACHE', data)
            }
        },
    },
    // 外部方法 commit触发--->mutaions  同步变更
    mutations: {
        CACHE(state, data) {
            state.baseURL = data.baseURL
            state.ossURL = data.ossURL
            state.ossImage = data.ossImage
            state.ossFolder = data.ossFolder
            state.enable = data.enable

            window.sessionStorage.setItem(tokenKey, JSON.stringify(state))
        },
    }
}

export default config